import baseRequest from "@/utils/request";

/**
 * 重写request
 * @param config
 * @returns {Promise | Promise<unknown>}
 */
const request = function (config) {
  config.baseURL = process.env.VUE_APP_BASE_API + '/shipmentV2'
  return baseRequest(config)
}

/**
 * 保存发货计划+货件单
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function saveShippingPlanShipment(data){
  return request({
    url: '/saveShippingPlanShipment',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 下载货件单的箱标
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function downloadShipmentBoxLabel(id){
  return request({
    url: `/downloadShipmentBoxLabel/${id}`,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

export function downloadShipmentSystemLabelGoods(id){
  return request({
    url: `/downloadShipmentSystemLabelGoods/${id}`,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 删除货件单
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function deleteShipment(id){
  return request({
    url: `/deleteShipment/${id}`,
    method: 'delete',
    handleError: true,
  })
}

export function getShipmentList(params = {}){
  return request({
    url: '/getShipmentList',
    params,
  })
}


export function editRemark(data){
  return request({
    url: '/editRemark',
    method: 'patch',
    data,
  })
}
